{extend name='common/common' /}

{block name="content"}
<div class="ibox-title">
    <h5>数据表列表</h5>
</div>
<div class="ibox-content">
	<div id="table-box">
		<el-table :data="tableData" stripe="true" border>
			<el-table-column prop="{$database_name}" label="表名"></el-table-column>
			<el-table-column prop="alls" label="记录数" width="150"></el-table-column>
			<el-table-column prop="ctime" label="上次备份时间" width="200"></el-table-column>
			<el-table-column prop="operate" label="操作" width="200">
				<template slot-scope="scope">
					<el-button
						@click="backData(scope.row)"
						size="small" plain type="success"
						icon="el-icon-edit"> 备份
					</el-button>
					<el-button
						@click="importData(scope.row)"
						size="small" plain 	type="danger"
						icon="el-icon-delete"> 还原
					</el-button>
				</template>
			</el-table-column>
		</el-table>
	</div>
</div>
{/block}

{block name="script"}
<script type="text/javascript">
var main = new Vue({
	el:"#main",
	data() {
		return {
			loading:false,
			searchText:'',
			tableData:''
		}
	},
	mounted:function() {
		this.getTable();
	},
	methods:{
		getTable() {
			this.loading = true;
			$.getJSON('./index',function(res){
				main.loading = false;
				if(res.code == 1){
					main.$message({
			          message: res.msg,
			          type: 'success'
			        });
					main.tableData = res.data.rows
				}else{
					main.$notify.error({
						title: '失败',
						message: res.msg,
					});
				}
			})
		},
		importData(row) {
			this.loading = true;
			$.getJSON("{:url('data/backData')}",{
				'table' : row.{$database_name}
			},function(res){
				main.loading = false;
				if(res.code == 1){
					main.$notify({
						title:"成功",
			          	message: '还原成功',
			          	type: 'success'
			        });
					main.getTable();
				}else{
					main.$notify.error({
						title: '失败',
						message: res.msg,
					});
				}
			});
		},
		backData(row) {
			this.loading = true;
			$.getJSON("{:url('data/importData')}",{
				'table':row.{$database_name}
			},function(res){
				main.loading = false;
				if(res.code == 1){
					main.$notify({
						title:"成功",
			          	message: '备份成功',
			          	type: 'success'
			        });
					main.getTable();
				}else{
					main.$notify.error({
						title: '失败',
						message: res.msg,
					});
				}
			});
		}
	}
})
</script>
{/block}
